package cn.qingyun.gis.modules.init.utils;

import cn.qingyun.gis.modules.express.util.ThreadPoolTool;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;

@Slf4j
public class FutureTool {
    public static <T> T get(Future<T> future) {
        try {
            return future.get(10, TimeUnit.SECONDS);
        } catch (Exception e) {
            log.warn("运行时异常", e);
            return null;
        }
    }

    public static <T> Future<T> getFuture(Supplier<T> supplier) {
        return ThreadPoolTool.singletonExecutor().submit(supplier::get);
    }
}
